const render = require("../../lib/bottom_nav");
require("../../assets/css/index.less")
require("../../assets/css/common.less");
require("./course.less")
const rendermytop = require("../../lib/mytop")


function $(select) {
    return document.querySelector(select)
}

const request = require("../../lib/requst")
let API = "http://fitness.h5.itsource.cn:3701"
window.onload = () => {
    request.get("/api/train/courseList").then(res => {
        console.log(res.data.data)
        let html = ""
        html = `
         <a href="./prj_idt.html?id=1" class="prj_wrap df fdc">       
             <div class="tu_top">
                 <img alt="" src ="${API + res.data.data[0].imgurl}" class="img">
             </div>
             <div class="itd df fdc">
                 <span class="title1">${res.data.data[0].name}</span>
                 <span class="title2">${res.data.data[1].desc}</span>
             </div>
         </a>
         `
        let div = document.createElement("div");
        div.className = "new_prj df"
        div.innerHTML = html;
        $(".main").append(div)

        let html2 = ""
        let arr = [
            {
                imgpath: API + res.data.data[1].imgurl,
                title1: res.data.data[1].name,
                title2: res.data.data[1].desc
            },
            {
                imgpath: API + res.data.data[2].imgurl,
                title1: res.data.data[2].name,
                title2: res.data.data[2].desc
            },
            {
                imgpath: API + res.data.data[3].imgurl,
                title1: res.data.data[3].name,
                title2: res.data.data[3].desc
            }
        ]

        html2 = arr.map(function (v, i) {

         return `${i == 0 ? "<h3>课程</h3>" : ""}
         <div class="privous_prj comm">
         <a href="" class="box_a comm5">
         <img  alt="" src = "${v.imgpath}" class="comm4">
         <span class="comm2">${v.title1}</span>
         <span class="comm3">${v.title2}</span>
         </a>
         </div>`   
            
        }).join("")
        console.log(html2)
        let div2 = document.createElement("div");
        div2.innerHTML = html2;
        // console.log(div2)
        $(".main").append(div2)
    })
    rendermytop("course")
    render("run");
}